﻿using System;
using System.Collections.Generic;
using System.Text;
using TextProcessingLibrary;

namespace MusicBee2Traktor
{
    class iTunesConverter
    {
        private readonly IEnumerable<ProcessingTask> _tasks;


        public iTunesConverter(IEnumerable<ProcessingTask> tasks)
        {
            _tasks = tasks;
        }


        public void Convert(string pathToITunesXml, string pathToOutputXml)
        {
            // load MusicBee iTunes.xml
            var iTunesXml = TextHelper.LoadWithProgress(pathToITunesXml);

            Console.WriteLine();

            if (_tasks != null)
            {
                Console.WriteLine();

                // execute tasks
                foreach (var task in _tasks)
                {
                    Console.WriteLine(task.Name);
                    task.Execute(ref iTunesXml);
                }

                Console.WriteLine();
            }

            // save Traktor iTunes.xml
            Encoding outputEncoding = new UTF8Encoding(false);
            TextHelper.SaveWithProgress(pathToOutputXml, iTunesXml, outputEncoding);
        }
    }
}
